<template>
  <div class="form form-readonly">
    <div class="group">
      <div class="label">编号</div>
      <div class="txt">{{ state.starinfo?.checkin2?.checkin_no }}</div>
    </div>
    <div class="group">
      <div class="label">姓名</div>
      <div class="txt">{{ state.starinfo?.star?.name }}</div>
    </div>
    <div class="group">
      <div class="label">年龄</div>
      <div class="txt">{{ state.starinfo?.register?.age }}岁</div>
    </div>
    <div class="group">
      <div class="label">身高</div>
      <div class="txt">{{ state.starinfo?.register?.height }}cm</div>
    </div>
    <div class="group">
      <div class="label">履历</div>
      <div class="txt">{{ state.starinfo?.register?.history }}</div>
    </div>
    <div class="group">
      <div class="label">现场照片</div>
      <div class="imgs">
        <img
          @click="imgShow"
          v-for="(item, index) in photos"
          :key="index"
          :src="item"
        />
      </div>
    </div>
    <div class="group">
      <div class="label">初试评语</div>
      <div class="txt">
        {{ state.starinfo?.register?.prtest_say || "" }}
        <div class="tags">
          <span v-for="(item, index) in tags" :key="index">{{ item }}</span>
        </div>
      </div>
    </div>
    <div class="comment second-comment">
      <div class="radios">
        <label>
          <input
            type="radio"
            value="1"
            :checked="state.starinfo?.register?.retest_result == 1"
            :disabled="disabled"
            name="retest_result"
            @change="radioChange"
          />
          <span>进组</span>
        </label>
        <label>
          <input
            type="radio"
            value="2"
            :checked="state.starinfo?.register?.retest_result == 2"
            :disabled="disabled"
            name="retest_result"
            @change="radioChange"
          />
          <span>未进组</span>
        </label>
      </div>
    </div>
    <button class="submit" @click="submit" :disabled="disabled">确定</button>
  </div>
</template>

<script setup>
import { useRouter, useRoute } from "vue-router";
import ajax from "../../util/http";
import { reactive, ref, computed, getCurrentInstance } from "vue";
const { proxy } = getCurrentInstance();

const router = useRouter();
const route = useRoute();
const state = reactive({
  starinfo: {},
  retest_result: 0,
});

const disabled = computed(() => {
  if (state.starinfo?.register?.retest_result) {
    return true;
  } else {
    return false;
  }
});

const photos = computed(() => {
  if (state.starinfo?.register?.prtest_photo) {
    return state.starinfo.register.prtest_photo.split(",");
  }
});
const tags = computed(() => {
  if (state.starinfo?.register?.prtest_tags) {
    return state.starinfo.register.prtest_tags.split("，");
  }
});

ajax({
  url: "/star/scene/oper_table",
  method: "post",
  data: {
    token: JSON.parse(localStorage.getItem("userinfo")).token,
    checkin_no: route.query.checkin_no,
    checkin_stage: 2,
  },
}).then((res) => {
  if (res.code == 1) {
    state.starinfo = res.data;
  }
});

const radioChange = (e) => {
  state.retest_result = e.target.value;
};

const imgShow = (e) => {
  proxy.$popup({
    img: e.target.getAttribute("src"),
  });
};

const submit = () => {
  if (!state.retest_result) {
    proxy.$message({ content: "请选择复试结果" });
  } else {
    ajax
      .post("/star/scene/modi_table", {
        token: JSON.parse(localStorage.getItem("userinfo")).token,
        checkin_id: state.starinfo.checkin2.id,
        retest_result: state.retest_result,
      })
      .then((res) => {
        if (res.code == 1) {
          router.push("/second/success");
        }
      });
  }
};
</script>